class VerificationUI extends egret.Sprite {

    public constructor() {
        super();
        //this.createView();
        this.once(egret.Event.ADDED_TO_STAGE, this.createView, this);
    }
    private createView(): void {
        // JsonpReq.process("./resource/assets/js/jquery-2.1.0.js");
        // JsonpReq.process("./resource/assets/js/jquery.md5.js");
        //添加背景
        // var bg = createBitmap("bg_png");
        // this.addChild(bg);
        //添加logo
        var logo = createBitmap("yz_logo_png", 418, 39);
        this.addChild(logo);
        //添加标题
        var title = createTextFiled("加入安联会员大家庭即刻抽奖！", 100, 200, 50, 0xffffff, "left", 460, 120);
        title.bold = true;
        this.addChild(title);
        //添加文本(请输入您的手机号)
        var tel_text = createTextFiled("请输入您的手机号", 100, 375, 29, 0xffffff);
        tel_text.bold = true;
        this.addChild(tel_text);
        //添加文本(短信验证码)
        var yzm_text = createTextFiled("短信验证码", 100, 694, 29, 0xffffff);
        yzm_text.bold = true;
        this.addChild(yzm_text);
        //添加文本输入框(输入手机号码文本框)
        var tel_input = drawReactShape("", 100, 420, 450, 66, 0xffffff);
        this.addChild(tel_input);
        var tel_input_tetx = createTextFiled("", 130, 420, 30, 0xfe3c63, "left", 390, 66, "middle", false, 0x000000, false, egret.TextFieldType.INPUT);
        this.addChild(tel_input_tetx);
        //添加文本输入框(输入验证码输入框)
        var yzm_input = drawReactShape("", 100, 743, 450, 66, 0xffffff);
        this.addChild(yzm_input);
        var yzm_input_tetx = createTextFiled("", 130, 743, 30, 0xfe3c63, "left", 390, 66, "middle", false, 0x000000, false, egret.TextFieldType.INPUT);
        this.addChild(yzm_input_tetx);

        //添加按钮(获取验证码)
        var hq_yz_buttom = my_button("获取验证码", 30, 0xfe3c63, true, 237, 107, 100, 547, "btn1_top_bg_png", 3, 0xfff530)
        this.addChild(hq_yz_buttom);
        //添加按钮(点击验证)
        var dj_yz_buttom = my_button("点击验证", 52, 0xfe3c63, true, 445, 128, 100, 865, "btn2_top_bg_png", 6, 0xfff530)
        this.addChild(dj_yz_buttom);
        //出错显示文本
        var tel_chucuo_tetx = createTextFiled("", 100, 500, 25, 0xfe3c63);
        this.addChild(tel_chucuo_tetx);
        var yzm_chucuo_tetx = createTextFiled("", 100, 825, 25, 0xfe3c63);
        this.addChild(yzm_chucuo_tetx);
        //手机正则验证
        tel_input_tetx.addEventListener(egret.TouchEvent.FOCUS_OUT, function () {

        }, this)
        //获取验证码点击获取验证码事件
        hq_yz_buttom.touchEnabled = true;
        var telNum;
        hq_yz_buttom.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
            if (/^1[3|5|7|8]\d{9}$/gi.test(tel_input_tetx.text)) {
                telNum = tel_input_tetx.text;
                MYajax({ "phone": telNum }, "http://swin.bluej.cn/index.php/Home/app/verification_code.html", function (res) {
                    console.log(res);
                    tel_chucuo_tetx.text="";
                })
            } else {
                tel_chucuo_tetx.text="请输入正确的手机号码";
            }
        }, this)
        //验证验证码
        var This=this;
        dj_yz_buttom.touchEnabled = true;
        dj_yz_buttom.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
            console.log(yzm_input_tetx.text)
            MYajax({ "phone": telNum, "code": yzm_input_tetx.text }, "http://swin.bluej.cn/index.php/Home/app/verification_phone.html", function (res) {
                console.log(res.state)
                if (res.state) {
                    // 这里验证成功
                    var luck_drawui = new Luck_drawUI();
                    This.stage.addChild(luck_drawui);
                    This.stage.removeChild(This);
                    yzm_chucuo_tetx.text="";
                } else {
                    yzm_chucuo_tetx.text="验证码输入有误";
                }
            })
        }, this)
    }

}
